// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package user

import (
	"context"
	"encoding/json"
	"fmt"

	"audio-server/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginOutLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginOutLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginOutLogic {
	return &LoginOutLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginOutLogic) LoginOut() (resp bool, err error) {
	userId, _ := l.ctx.Value("userId").(json.Number).Int64()
	key := "accessToken:" + fmt.Sprint(userId)
	del, err := l.svcCtx.Redis.Del(key)
	if err != nil {
		return false, err
	}
	return del > 0, err
}
